package com.zhongxia.controller;

import com.zhongxia.entity.Menu;
import com.zhongxia.entity.Order;
import com.zhongxia.entity.OrderVO;
import com.zhongxia.entity.User;
import com.zhongxia.feign.OrderFeign;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.util.Date;

/**
 * @Author: 废柴弟弟
 * @Date: 2020/4/9 18:47
 */
@Controller
@RequestMapping("clientorder")
public class ClientOrder {
    @Autowired
    private OrderFeign orderFeign;
    @GetMapping("/save/{mid}")
    public String save(@PathVariable("mid") int mid, HttpSession session){
        User user = (User) session.getAttribute("user");
        Order order = new Order();
        Menu menu = new Menu();
        menu.setId(mid);
        order.setUser(user);
        order.setMenu(menu);
        orderFeign.save(order);
        return "order";
    }

    @GetMapping("/findAllByUid")
    @ResponseBody
    public OrderVO findAllByUid(@RequestParam("page") int page, @RequestParam("limit") int limit, HttpSession session){
        User user = (User) session.getAttribute("user");
        int index=(page-1)*limit;
        return orderFeign.findAllByUid(index,limit,user.getId());
    }
    @GetMapping("order")
    public String order()
    {
        return "order";
    }
    @GetMapping("manage")
    public String manage()
    {
        return "order_manage";
    }
    @GetMapping("/findAll")
    @ResponseBody
    public OrderVO findAll(@RequestParam("page") int page, @RequestParam("limit") int limit){
        int index=(page-1)*limit;
        return orderFeign.findAll(index, limit);
    }

    @GetMapping("/update/{id}")
    public String update(@PathVariable("id") int id){

        orderFeign.update(id);
        return "order_manage";
    }
}
